﻿<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>oracle12c数据库安装（静默安装）</title>
  <link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>

<body class="stackedit">
  <div class="stackedit__html"><p></p><div class="toc"><h3>目录</h3><ul><ul><ul><li><a href="#_2">前言</a></li><li><a href="#1__5">1. 安装前准备工作</a></li><li><a href="#2__148">2. 安装数据库软件</a></li><li><a href="#3__169">3. 配置监听</a></li><li><a href="#4__188">4. 创建数据库</a></li></ul></ul></ul></div><p></p>
<h3><a id="_2"></a>前言</h3>
<p>本教程是在Linux下安装oracle12c数据库，由于在有些情况下并没有图形化安装界面，所以这里介绍在linux下通用的安装方式：静默安装，通俗的说就是在linux的命令行窗口安装，这里使用的是oracle linux7.6。</p>
<h3><a id="1__5"></a>1. 安装前准备工作</h3>
<p>（1）关闭防火墙<br>
执行以下命令禁用并关闭防火墙</p>
<pre><code class="prism language-handlebars"><span class="token variable">systemctl</span>  <span class="token variable">disable</span>  <span class="token variable">firewalld</span>
<span class="token variable">systemctl</span>  <span class="token variable">stop</span>  <span class="token variable">firewalld</span>
</code></pre>
<p>（2）关闭selinux<br>
执行vim /etc/selinux/config修改编辑config文件,将SELINUX设置成disabled，如下所示<br>
<img src="https://img-blog.csdnimg.cn/538f19ffa113464d888bfc5cf4d59ae8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>（3）修改Linux内核参数<br>
执行vim /etc/sysctl.conf，在sysctl.conf文件末尾添加如下参数，然后执行sysctl -p命令，使得配置的内核参数生效</p>
<pre><code class="prism language-handlebars"><span class="token variable">fs</span><span class="token punctuation">.</span><span class="token variable">aio-max-nr</span><span class="token punctuation">=</span><span class="token number">1048576</span>
<span class="token variable">fs</span><span class="token punctuation">.</span><span class="token variable">file-max</span><span class="token punctuation">=</span><span class="token number">6815744</span>
<span class="token variable">kernel</span><span class="token punctuation">.</span><span class="token variable">sem</span><span class="token punctuation">=</span><span class="token number">250</span> <span class="token number">32000</span> <span class="token number">100</span> <span class="token number">128</span>
<span class="token variable">kernel</span><span class="token punctuation">.</span><span class="token variable">shmall</span><span class="token punctuation">=</span><span class="token number">2097152</span>
<span class="token variable">kernel</span><span class="token punctuation">.</span><span class="token variable">shmmax</span><span class="token punctuation">=</span><span class="token number">2147483648</span>
<span class="token variable">kernel</span><span class="token punctuation">.</span><span class="token variable">shmmni</span><span class="token punctuation">=</span><span class="token number">4096</span>
<span class="token variable">net</span><span class="token punctuation">.</span><span class="token variable">core</span><span class="token punctuation">.</span><span class="token variable">rmem_default</span><span class="token punctuation">=</span><span class="token number">1048576</span>
<span class="token variable">net</span><span class="token punctuation">.</span><span class="token variable">core</span><span class="token punctuation">.</span><span class="token variable">rmem_max</span><span class="token punctuation">=</span><span class="token number">4194304</span>
<span class="token variable">net</span><span class="token punctuation">.</span><span class="token variable">core</span><span class="token punctuation">.</span><span class="token variable">wmem_default</span><span class="token punctuation">=</span><span class="token number">262144</span>
<span class="token variable">net</span><span class="token punctuation">.</span><span class="token variable">core</span><span class="token punctuation">.</span><span class="token variable">wmem_max</span><span class="token punctuation">=</span><span class="token number">1048576</span>
<span class="token variable">net</span><span class="token punctuation">.</span><span class="token variable">ipv4</span><span class="token punctuation">.</span><span class="token variable">ip_local_port_range</span><span class="token punctuation">=</span><span class="token number">9000</span> <span class="token number">65500</span>
</code></pre>
<p>（4）安装Oracle12c的依赖包<br>
yum安装oracle数据库所需要依赖包，如果一次安装失败，可以多试几次，是可以安装成功的</p>
<pre><code class="prism language-handlebars"><span class="token variable">yum</span> <span class="token variable">install</span> <span class="token variable">binutils</span> <span class="token variable">gcc</span> <span class="token variable">gcc-c</span><span class="token punctuation">+</span><span class="token punctuation">+</span> <span class="token variable">glibc</span> <span class="token variable">glibc-devel</span> <span class="token variable">ksh</span> <span class="token variable">libaio</span> <span class="token variable">libaio-devel</span> <span class="token variable">libgcc</span> <span class="token variable">libstdc</span><span class="token punctuation">+</span><span class="token punctuation">+</span> <span class="token variable">libstdc</span><span class="token punctuation">+</span><span class="token punctuation">+</span><span class="token variable">-devel</span> <span class="token variable">libXext</span> <span class="token variable">libXtst</span> <span class="token variable">libX11</span> <span class="token variable">libXau</span> <span class="token variable">libxcb</span> <span class="token variable">libXi</span> <span class="token variable">make</span> <span class="token variable">sysstat</span> <span class="token variable">libnsl</span><span class="token punctuation">.</span><span class="token variable">x86_64</span>
</code></pre>
<p>（5）创建Oracle用户和用户组<br>
依次执行下面命令创建oracle用户和用户组，然后后执行id oracle，如果显示如下图那样，说明创建成功</p>
<pre><code class="prism language-handlebars"><span class="token variable">groupadd</span> <span class="token variable">oinstall</span>
<span class="token variable">groupadd</span> <span class="token variable">dba</span>
<span class="token variable">useradd</span> <span class="token variable">-g</span> <span class="token variable">oinstall</span> <span class="token variable">-G</span> <span class="token variable">dba</span> <span class="token variable">oracle</span>
<span class="token variable">echo</span> <span class="token string">"oracle"</span> <span class="token punctuation">|</span> <span class="token variable">passwd</span> <span class="token variable">oracle</span> <span class="token variable">--stdin</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/f7c3619a7b0845afb7e395aadaa25221.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>（6）修改oracle用户权限文件<br>
执行vim /etc/security/limits.conf，在文件中添加以下内容</p>
<pre><code class="prism language-handlebars"><span class="token variable">oracle</span>  <span class="token variable">soft</span>    <span class="token variable">nofile</span>  <span class="token number">65536</span>
<span class="token variable">oracle</span>  <span class="token variable">hard</span>    <span class="token variable">nofile</span>  <span class="token number">65536</span>
<span class="token variable">oracle</span>  <span class="token variable">soft</span>    <span class="token variable">nproc</span>   <span class="token number">2047</span>
<span class="token variable">oracle</span>  <span class="token variable">hard</span>    <span class="token variable">nproc</span>   <span class="token number">16384</span>
<span class="token variable">oracle</span>  <span class="token variable">soft</span>    <span class="token variable">stack</span>   <span class="token number">10240</span>
</code></pre>
<p>执行vim /etc/pam.d/login，在文件中添加以下内容</p>
<pre><code class="prism language-handlebars"><span class="token variable">session</span> <span class="token variable">required</span>        <span class="token punctuation">/</span><span class="token variable">lib64</span><span class="token punctuation">/</span><span class="token variable">security</span><span class="token punctuation">/</span><span class="token variable">pam_limits</span><span class="token punctuation">.</span><span class="token variable">so</span>
<span class="token variable">session</span> <span class="token variable">required</span>        <span class="token variable">pam_limits</span><span class="token punctuation">.</span><span class="token variable">so</span>
</code></pre>
<p>执行vim /etc/profile，在文件中添加以下内容,然后执行source  /etc/profile使得修改生效</p>
<pre><code class="prism language-handlebars"><span class="token block keyword">#oracle</span> <span class="token variable">config</span>
<span class="token variable">if</span> <span class="token punctuation">[</span> <span class="token variable">$USER</span> <span class="token punctuation">=</span> <span class="token string">"oracle"</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token variable">then</span>
  <span class="token variable">if</span> <span class="token punctuation">[</span> <span class="token variable">$SHELL</span> <span class="token punctuation">=</span> <span class="token string">"/bin/ksh"</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token variable">then</span>
      <span class="token variable">ulimit</span> <span class="token variable">-p</span> <span class="token number">16384</span>
      <span class="token variable">ulimit</span> <span class="token variable">-n</span> <span class="token number">65536</span>
  <span class="token variable">else</span>
      <span class="token variable">ulimit</span> <span class="token variable">-u</span> <span class="token number">16384</span> <span class="token variable">-n</span> <span class="token number">65536</span>
  <span class="token variable">fi</span>
<span class="token variable">fi</span>
</code></pre>
<p>（7）创建安装目录和文件权限</p>
<pre><code class="prism language-handlebars"><span class="token variable">mkdir</span> <span class="token variable">-p</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">product</span><span class="token punctuation">/</span><span class="token number">12.2</span><span class="token number">.0</span>
<span class="token variable">mkdir</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">oradata</span>
<span class="token variable">mkdir</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">inventory</span>
<span class="token variable">mkdir</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">fast_recovery_area</span>
<span class="token variable">chown</span> <span class="token variable">-R</span> <span class="token variable">oracle</span><span class="token punctuation">:</span><span class="token variable">oinstall</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span>
<span class="token variable">chmod</span> <span class="token variable">-R</span> <span class="token number">755</span> <span class="token block keyword">/u1/database/oracle/</span>
</code></pre>
<p>（8）配置Oracle环境变量<br>
执行vim /home/oracle/.bash_profile，在文件中添加如下内容，然后执行source /home/oracle/.bash_profile,使得环境变量生效</p>
<pre><code class="prism language-handlebars"><span class="token variable">umask</span> <span class="token number">022</span>
<span class="token variable">ORACLE_BASE</span><span class="token punctuation">=</span><span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span>
<span class="token variable">ORACLE_HOME</span><span class="token punctuation">=</span><span class="token variable">$ORACLE_BASE</span><span class="token punctuation">/</span><span class="token variable">product</span><span class="token punctuation">/</span><span class="token number">12.2</span><span class="token number">.0</span><span class="token block keyword">/dbhome_1</span>
<span class="token variable">ORACLE_SID</span><span class="token punctuation">=</span><span class="token variable">orcl</span>
<span class="token variable">PATH</span><span class="token punctuation">=</span><span class="token variable">$PATH</span><span class="token punctuation">:</span><span class="token variable">$ORACLE_HOME</span><span class="token punctuation">/</span><span class="token variable">bin</span>
<span class="token variable">LD_LIBRARY_PATH</span><span class="token punctuation">=</span><span class="token variable">$ORACLE_HOME</span><span class="token punctuation">/</span><span class="token variable">lib</span><span class="token punctuation">:</span><span class="token punctuation">/</span><span class="token variable">usr</span><span class="token punctuation">/</span><span class="token number">12.2</span><span class="token number">.0</span><span class="token block keyword">/lib:$LD_LIBRARY_PATH</span>
<span class="token variable">LANG</span><span class="token punctuation">=</span><span class="token variable">C</span>
<span class="token variable">export</span> <span class="token variable">ORACLE_BASE</span> <span class="token variable">ORACLE_HOME</span> <span class="token variable">ORACLE_SID</span> <span class="token variable">PATH</span> <span class="token variable">LD_LIBRARY_PATH</span> <span class="token variable">LANG</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/bfe97007e9154a999cebec64923ae9b1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
（9）编辑hosts和hostname文件</p>
<pre><code class="prism language-handlebars"><span class="token variable">执行vim</span>  <span class="token punctuation">/</span><span class="token variable">etc</span><span class="token punctuation">/</span><span class="token variable">hostname</span><span class="token punctuation">,</span><span class="token variable">添加如下内容</span>
<span class="token variable">jamysong</span>
<span class="token variable">执行vim</span>  <span class="token punctuation">/</span><span class="token variable">etc</span><span class="token punctuation">/</span><span class="token variable">hosts，添加如下内容，这里</span><span class="token number">192.168</span><span class="token number">.227</span><span class="token number">.73</span><span class="token variable">地址可以通过执行ifconfig查询到</span>
<span class="token number">192.168</span><span class="token number">.227</span><span class="token number">.73</span>   <span class="token variable">jamysong</span>      
<span class="token variable">然后执行init</span> <span class="token number">6</span><span class="token variable">重启后，可以看到修改已经生效</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/3ab9d09e099e479d8c9698cea5edfd5f.png" alt="在这里插入图片描述"><br>
（10）上传oracle12c的二进制安装包并解压<br>
<a href="https://edelivery.oracle.com/osdc/faces/SoftwareDelivery">官方下载地址</a><br>
这里将linuxx64_12201_database.zip上传到/usr/local/src文件夹下，然后执行unzip  linuxx64_12201_database.zip来解压<br>
<img src="https://img-blog.csdnimg.cn/27b8b2cc26ea4d35a9ea41f31994a02e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
然后将reponse文件夹整个复制到/home/oracle/</p>
<pre><code class="prism language-handlebars"><span class="token variable">cp</span>  <span class="token variable">-R</span>  <span class="token punctuation">/</span><span class="token variable">usr</span><span class="token punctuation">/</span><span class="token variable">local</span><span class="token punctuation">/</span><span class="token variable">src</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">response</span>   <span class="token punctuation">/</span><span class="token variable">home</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span>
<span class="token variable">chmod</span>  <span class="token variable">-R</span>  <span class="token number">777</span>  <span class="token block keyword">/home/oracle/response</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/1b1212a8991246618a6e2c7e20d7b087.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/dcae5789ce5043d09a40e44beb63a3a4.png" alt="在这里插入图片描述"><br>
执行vim db_install.rsp,将db_install.rsp脚本中这些变量值设置成如下内容（有的参数修改值，没有的的参数新增即可）：</p>
<pre><code class="prism language-handlebars"><span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">option</span><span class="token punctuation">=</span><span class="token variable">INSTALL_DB_SWONLY</span>
<span class="token variable">ORACLE_HOSTNAME</span><span class="token punctuation">=</span><span class="token variable">jamysong</span>  
<span class="token variable">UNIX_GROUP_NAME</span><span class="token punctuation">=</span><span class="token variable">oinstall</span>
<span class="token variable">INVENTORY_LOCATION</span><span class="token punctuation">=</span><span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">inventory</span>
<span class="token variable">SELECTED_LANGUAGES</span><span class="token punctuation">=</span><span class="token variable">en</span><span class="token punctuation">,</span><span class="token variable">zh_CN</span>
<span class="token variable">ORACLE_HOME</span><span class="token punctuation">=</span><span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">product</span><span class="token punctuation">/</span><span class="token number">12.2</span><span class="token number">.0</span><span class="token block keyword">/dbhome_1</span>
<span class="token variable">ORACLE_BASE</span><span class="token punctuation">=</span><span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">InstallEdition</span><span class="token punctuation">=</span><span class="token variable">EE</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">OSDBA_GROUP</span><span class="token punctuation">=</span><span class="token variable">dba</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">OSOPER_GROUP</span><span class="token punctuation">=</span><span class="token variable">dba</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">OSBACKUPDBA_GROUP</span><span class="token punctuation">=</span><span class="token variable">dba</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">OSDGDBA_GROUP</span><span class="token punctuation">=</span><span class="token variable">dba</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">OSKMDBA_GROUP</span><span class="token punctuation">=</span><span class="token variable">dba</span>
<span class="token variable">oracle</span><span class="token punctuation">.</span><span class="token variable">install</span><span class="token punctuation">.</span><span class="token variable">db</span><span class="token punctuation">.</span><span class="token variable">OSRACDBA_GROUP</span><span class="token punctuation">=</span><span class="token variable">dba</span>
<span class="token variable">DECLINE_SECURITY_UPDATES</span><span class="token punctuation">=</span><span class="token boolean">true</span>
</code></pre>
<h3><a id="2__148"></a>2. 安装数据库软件</h3>
<p>先切换到oracle用户下执行安装数据库软件，如果出现如下页面表示安装成功</p>
<pre><code class="prism language-handlebars"><span class="token variable">su</span>  <span class="token variable">oracle</span>
<span class="token variable">source</span> <span class="token punctuation">/</span><span class="token variable">home</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token punctuation">.</span><span class="token variable">bash_profile</span>
<span class="token variable">cd</span> <span class="token punctuation">/</span><span class="token variable">usr</span><span class="token punctuation">/</span><span class="token variable">local</span><span class="token punctuation">/</span><span class="token variable">src</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span>
<span class="token punctuation">.</span><span class="token punctuation">/</span><span class="token variable">runInstaller</span> <span class="token variable">-silent</span> <span class="token variable">-responseFile</span> <span class="token punctuation">/</span><span class="token variable">home</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">response</span><span class="token punctuation">/</span><span class="token variable">db_install</span><span class="token punctuation">.</span><span class="token variable">rsp</span> <span class="token variable">-ignorePrereq</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/4d5407a775b644c59b1a5ec26dbe40a7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>然后切换到root用户下执行下面命令</p>
<pre><code class="prism language-handlebars"><span class="token variable">su</span> <span class="token variable">root</span> 
<span class="token variable">sh</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">inventory</span><span class="token punctuation">/</span><span class="token variable">orainstRoot</span><span class="token punctuation">.</span><span class="token variable">sh</span>
<span class="token variable">sh</span> <span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">product</span><span class="token punctuation">/</span><span class="token number">12.2</span><span class="token number">.0</span><span class="token block keyword">/dbhome_1/root.sh</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/c7e1d0b0178e4744908fea208042c558.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<h3><a id="3__169"></a>3. 配置监听</h3>
<p>再次执行su oracle切换到oracle用户下执行下面命令，此时直接执行可能会报如下错误</p>
<pre><code class="prism language-handlebars"><span class="token variable">netca</span> <span class="token punctuation">/</span><span class="token variable">silent</span> <span class="token punctuation">/</span><span class="token variable">responseFile</span> <span class="token punctuation">/</span><span class="token variable">home</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">response</span><span class="token punctuation">/</span><span class="token variable">netca</span><span class="token punctuation">.</span><span class="token variable">rsp</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/51b792ee68824162bd23ebe5e8bb9498.png" alt="在这里插入图片描述"><br>
那么先执行下source  ~/.bash_profile,如果出现如图所示，那么就可以执行上面的命令了<br>
<img src="https://img-blog.csdnimg.cn/9422c4a84f824716931c24e0dba0230b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
再次执行netca /silent /responseFile /home/oracle/response/netca.rsp，看到如下图就说明监听成功启动<br>
<img src="https://img-blog.csdnimg.cn/fcfd9e322c6e400dafcbd63a787a3ce1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
执行netstat -tunlp | grep 1521，查看监听的端口号，如下图所示这样，到此监听配置完毕<br>
<img src="https://img-blog.csdnimg.cn/e254fe32283d4b7da12928d0a2ddaf4f.png" alt="在这里插入图片描述"></p>
<pre><code class="prism language-handlebars"><span class="token variable">查看监听状态</span>  <span class="token variable">lsnrctl</span> <span class="token variable">status</span>
<span class="token variable">启动监听器：</span>  <span class="token variable">lsnrctl</span> <span class="token variable">start</span>                     
<span class="token variable">关闭监听器：</span>  <span class="token variable">lsnrctl</span> <span class="token variable">stop</span>
</code></pre>
<h3><a id="4__188"></a>4. 创建数据库</h3>
<p>执行vim /home/oracle/response/dbca.rsp命令编辑文件，设置以下内容，下面两个应答文件二选一即可</p>
<p><em>应答文件一：使用此应答文件创建的数据库在创建用户时需要在用户名前加上C##</em></p>
<pre><code class="prism language-handlebars"><span class="token variable">responseFileVersion</span><span class="token punctuation">=</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">assistants</span><span class="token punctuation">/</span><span class="token variable">rspfmt_dbca_response_schema_v12</span><span class="token punctuation">.</span><span class="token number">2.0</span>
<span class="token variable">gdbName</span><span class="token punctuation">=</span><span class="token variable">orcl</span>
<span class="token variable">sid</span><span class="token punctuation">=</span><span class="token variable">orcl</span>
<span class="token variable">databaseConfigType</span><span class="token punctuation">=</span><span class="token variable">SI</span>
<span class="token variable">createAsContainerDatabase</span><span class="token punctuation">=</span><span class="token boolean">true</span>
<span class="token variable">numberOfPDBs</span><span class="token punctuation">=</span><span class="token number">1</span>
<span class="token variable">pdbName</span><span class="token punctuation">=</span><span class="token variable">orclpdb</span>
<span class="token variable">templateName</span><span class="token punctuation">=</span><span class="token punctuation">/</span><span class="token variable">u1</span><span class="token punctuation">/</span><span class="token variable">database</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">product</span><span class="token punctuation">/</span><span class="token number">12.2</span><span class="token number">.0</span><span class="token block keyword">/dbhome_1/assistants/dbca/templates/General_Purpose.dbc</span>
<span class="token variable">emExpressPort</span><span class="token punctuation">=</span><span class="token number">5500</span>
<span class="token variable">omsPort</span><span class="token punctuation">=</span><span class="token number">0</span>
<span class="token variable">characterSet</span><span class="token punctuation">=</span><span class="token variable">AL32UTF8</span>
<span class="token variable">listeners</span><span class="token punctuation">=</span><span class="token variable">LISTENER</span>
<span class="token variable">memoryPercentage</span><span class="token punctuation">=</span><span class="token number">40</span>
<span class="token variable">automaticMemoryManagement</span><span class="token punctuation">=</span><span class="token boolean">false</span>
<span class="token variable">totalMemory</span><span class="token punctuation">=</span><span class="token number">0</span>
</code></pre>
<p><em>应答文件二：使用此应答文件创建的数据库在创建用户时不需要在用户名前加上C##</em></p>
<pre><code>responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=orcl
sid=orcl
databaseConfigType=SI
createAsContainerDatabase=false
templateName=/u1/database/oracle/product/12.2.0/dbhome_1/assistants/dbca/templates/General_Purpose.dbc
emExpressPort=5500
omsPort=0
characterSet=AL32UTF8
listeners=LISTENER
memoryPercentage=40
automaticMemoryManagement=false
totalMemory=800
</code></pre>
<p>然后执行如下命令创建数据库实例，分别要给SYS,SYSTEM,PDBADMIN三个用户设置密码</p>
<pre><code class="prism language-handlebars"><span class="token variable">dbca</span> <span class="token variable">-silent</span> <span class="token variable">-createDatabase</span>  <span class="token variable">-responseFile</span>  <span class="token punctuation">/</span><span class="token variable">home</span><span class="token punctuation">/</span><span class="token variable">oracle</span><span class="token punctuation">/</span><span class="token variable">response</span><span class="token punctuation">/</span><span class="token variable">dbca</span><span class="token punctuation">.</span><span class="token variable">rsp</span>
</code></pre>
<p>如图所示，表示创建数据库实例完成<br>
<img src="https://img-blog.csdnimg.cn/b764d163f5fd47cdbecbca81fc30dea6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
登录数据库</p>
<pre><code class="prism language-handlebars"><span class="token variable">sqlplus</span> <span class="token punctuation">/</span> <span class="token variable">as</span> <span class="token variable">sysdba</span>
</code></pre>
<p>创建数据库用户</p>
<pre><code class="prism language-handlebars"><span class="token variable">create</span> <span class="token variable">user</span> <span class="token variable">用户名</span> <span class="token variable">identified</span> <span class="token variable">by</span> <span class="token variable">口令</span><span class="token brackets"><span class="token punctuation">[</span><span class="token variable">即密码</span><span class="token punctuation">]</span></span><span class="token punctuation">;</span>
<span class="token variable">例如</span><span class="token punctuation">:</span><span class="token variable">create</span> <span class="token variable">user</span> <span class="token variable">c</span><span class="token punctuation">#</span><span class="token punctuation">#</span><span class="token variable">jamy</span> <span class="token variable">identified</span> <span class="token variable">by</span> <span class="token number">123456</span><span class="token punctuation">;</span>
<span class="token variable">这里一定注意：用户名前一定要加c</span><span class="token punctuation">#</span><span class="token punctuation">#</span><span class="token punctuation">,</span><span class="token variable">否则会报错</span>
</code></pre>
<p>给用户授权</p>
<pre><code class="prism language-handlebars"><span class="token variable">grant</span> <span class="token variable">connect</span><span class="token punctuation">,</span> <span class="token variable">resource，dba</span> <span class="token variable">to</span> <span class="token variable">用户名</span><span class="token punctuation">;</span>
<span class="token variable">例如：grant</span> <span class="token variable">connect</span><span class="token punctuation">,</span> <span class="token variable">resource</span><span class="token punctuation">,</span><span class="token variable">dba</span> <span class="token variable">to</span> <span class="token variable">c</span><span class="token punctuation">#</span><span class="token punctuation">#</span><span class="token variable">jamy</span><span class="token punctuation">;</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/c8153dcd54094a2ab3c98f876755c691.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
客户端工具Navicat登录数据库<br>
<img src="https://img-blog.csdnimg.cn/49b9f2faa402453abebe3c1a7d5fe0eb.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_18,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>
如果连接失败<br>
先考虑执行lsnrctl  start重启监听<br>
再执行sqlplus / as sysdba登录数据库<br>
执行startup;启动数据库实例如图所示<br>
<img src="https://img-blog.csdnimg.cn/d059036583e24a8b8cf5c13871345179.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiL6Zuo5aSp55qE5aSq6Ziz,size_13,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</div>
</body>

</html>
